<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Home extends Auth_Controller {

    public function index(){
        //Model
        $this->load->model('order_mdl');

        if(!$_SESSION['mobile']){
           if($_SESSION['group'] == 3){
                $this->users();
            }else{
                $this->admini();
            }
        }else{
            //手机端代码

            $this->_view('index');
        }
    }

    /**
     * 用户首页
     */
    private function users(){
        //查询是否有为结算的订单
        $uid = $_SESSION['user']['id'];

        $this->db->where('user_id',$uid);
        $this->db->where('status',4);
        $data['count'] = $this->order_mdl->get_count();

        //查询详细信息
        $this->db->where('id',$uid);
        $data['uinfo'] = $this->uinfo_mdl->get_one();

        $this->_view('index',$data);
    }

    /**
     * 管理员首页
     */
    private function admini(){
        $this->db->where('status',2);
        $data['count'] = $this->order_mdl->get_count();

        //查询统计登录次数
        $new_time = time();
        $this->load->model('session_mdl');
        $sess = array(); //访问量

        for($i = 0 ; $i <= 12; $i ++){
            $time = date('Y-m-d',$new_time-(60*60*24*$i));
            $begin = strtotime($time);
            $end = $begin+60*60*24;

            $this->db->where('login_time >=', $begin);
            $this->db->where('login_time <', $end);

            $sess[$i] = array(
                    'day' => date('m-d',$begin),
                    'b' => $begin,
                    'e' => $end,
                    'res' => $this->session_mdl->get_count()
            );
        }

        $sess_max = 0;
        foreach($sess as $k => $v){
            $num[] = $v['res'];
            $day[] = $v['day'];
            if($v['res'] > $sess_max){
                $sess_max = $v['res']+5;
            }
        }

        $data['sess']['num'] = json_encode($num);
        $data['sess']['day'] = json_encode($day);
        $data['sess']['max'] = $sess_max;

        $this->_view('admini',$data);
    }
}

/* End of file Home.php */
/* Location: ./application/controllers/Home.php */